package com.bw.controller;

import com.bw.domain.*;
import com.bw.service.*;
import com.bw.utils.common.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("goods")
@RestController
public class GoodsController {
    @Autowired
    QudaoService qudaoService;
    @Autowired
    AppidService appidService;
    @Autowired
    QdlxService qdlxService;
    @Autowired
    GsmcService gsmcService;
    @Autowired
    XtbbService xtbbService;

    @RequestMapping("list")
    public Result list(@RequestBody Qudao qudao, @RequestParam(defaultValue = "1")Integer pageNum){
        PageHelper.startPage(pageNum,3);
        List<Qudao> list = qudaoService.list(qudao);
        return Result.success(new PageInfo<>(list));
    }
    @Cacheable(value = "appidId")
    @RequestMapping("appidId")
    public Result appidId(){
        List<Appid> list = appidService.list();
        return Result.success(list);
    }
    @Cacheable(value = "qdlxId")
    @RequestMapping("qdlxId")
    public Result qdlxId(){
        List<Qdlx> list = qdlxService.list();
        return Result.success(list);
    }
    @Cacheable(value = "gsmcId")
    @RequestMapping("gsmcId")
    public Result gsmcId(){
        List<Gsmc> list = gsmcService.list();
        return Result.success(list);
    }
    @Cacheable(value = "xtbbId")
    @RequestMapping("xtbbId")
    public Result xtbbId(){
        List<Xtbb> list = xtbbService.list();
        return Result.success(list);
    }
    @RequestMapping("add")
    public Result add(@RequestBody Qudao qudao){
        boolean b = qudaoService.saveOrUpdate(qudao);
        return b?Result.success():Result.fail();
    }
}
